package com.example.service.impl;

import com.example.pojo.CodeTale;
import com.example.service.SmsCodeService;
import com.example.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;

@Service
public class SmsCodeServiceImpl implements SmsCodeService {

    @Autowired
    private CodeUtils codeUtils;

    @Override
    @CachePut(value = "smsCode",key = "#tela")
    public String sendUserCode(String tela) {
        String code = codeUtils.sendCode(tela);
        return code;
    }

    @Override
    public boolean checkCode(CodeTale codeTale) {
        String code = codeUtils.getCode(codeTale.getTale());
        return codeTale.getCode().equals(code);
    }
}
